Skip to content

Comments

feat: cache member attending event IDs to eliminate N+1 queries#2501

Merged
olleolleolle merged 1 commit intocodebar:masterfrom
mroderick:fix/member-attending-cache
Feb 23, 2026
Merged

feat: cache member attending event IDs to eliminate N+1 queries#2501
olleolleolle merged 1 commit intocodebar:masterfrom
mroderick:fix/member-attending-cache

Conversation

@mroderick
Copy link
Collaborator

Summary

  • Adds attending_event_ids method to Member model that caches all event/workshop/meeting IDs where member has accepted invitation
  • Updates MemberPresenter to use cache instead of per-event queries
  • Adds cache invalidation callbacks when invitation attending status changes

Motivation

The events and meetings index pages were making N+1 queries when checking if a logged-in member was attending each event.

Analysis

  • Before: 40 queries for 40 events
  • After: 3 queries (one each for invitations, workshop_invitations, meeting_invitations)
  • The cache returns a Set of all event IDs, making subsequent lookups O(1)

Test Plan

  • All existing tests pass
  • Manual verification with Bullet shows no N+1 queries for attending status

Motivation:
The events and meetings index pages were making N+1 queries when checking
if a logged-in member was attending each event. Each call to
@user.attending?(event) triggered a database query.

Analysis:
- Before: 40 queries for 40 events
- After: 3 queries (one each for invitations, workshop_invitations, meeting_invitations)
- The cache returns a Set of all event IDs where the member has an accepted
  invitation, making subsequent lookups O(1) Ruby operations.

The cache is invalidated when an invitation's attending status changes via
after_save callbacks on Invitation, WorkshopInvitation, and MeetingInvitation models.
This ensures the cache stays fresh on the next request after RSVP.
@mroderick mroderick marked this pull request as ready for review February 21, 2026 15:03
@olleolleolle olleolleolle merged commit 72f69f4 into codebar:master Feb 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants